home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / CEditKeyControlsDialog.cp < prev    next >
Text File  |  1994-05-02  |  8KB  |  229 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| CEditKeyControlsDialog.cp
  3. //|
  4. //| This implements the dialog used to edit a key control
  5. //|_________________________________________________________
  6.  
  7. #include "CEditKeyControlsDialog.h"
  8. #include "CModifierKeyPane.h"
  9.  
  10. #include "HyperCuber Balloons.h"
  11. #include "HyperCuber Commands.h"
  12.  
  13. #include <CBartender.h>
  14. #include <CButton.h>
  15. #include <CDecorator.h>
  16. #include <CEditText.h>
  17. #include <CIntegerText.h>
  18. #include <CPaneBorder.h>
  19. #include <CPopupMenu.h>
  20. #include <CStdPopupPane.h>
  21.  
  22. #include <ctype.h>
  23. #include <string.h>
  24.  
  25. //============================ Globals ===============================\\
  26.  
  27. extern CDecorator         *gDecorator;
  28. extern CBartender         *gBartender;
  29.  
  30.  
  31.  
  32. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. //| CEditKeyControlsDialog::IEditKeyControlsDialog
  34. //|
  35. //| Purpose: Initialize the dialog.
  36. //|
  37. //| Parameters: WindowID:   ID of WIND resource to use
  38. //|             enclosure:  the Desktop
  39. //|             supervisor: the supervisor of this DialogDirector
  40. //|             key:        the key to edit
  41. //|______________________________________________________________________________
  42.  
  43. void CEditKeyControlsDialog::IEditKeyControlsDialog(short WindowID, CDesktop *enclosure,
  44.                                             CDirector *supervisor, key_control_struct *key)
  45. {
  46.  
  47.     
  48. #define OKAY_BUTTON_ID        130
  49. #define CANCEL_BUTTON_ID    131
  50.  
  51. #define FUNCTION_HEIGHT        40
  52. #define DIRECTION_MENU_ID    131
  53. #define DIMENSION_MENU_ID    30000
  54. #define ANGLE_MENU_ID        30001
  55.  
  56.     CDialog::IDialog(WindowID, enclosure, supervisor);        //  Initialize window from WIND resource
  57.  
  58.     helpResID = WINDOW_HELP_RES;                            //  Link in the Balloon Help
  59.  
  60.     CButton        *button;
  61.     button = new(CButton);                                    //  Set up the okay button
  62.     button->IButton(OKAY_BUTTON_ID, this, this);
  63.     button->Offset(320, FUNCTION_HEIGHT + 40, TRUE);
  64.     button->SetClickCmd (cmdOK);
  65.     button->helpResIndex = kKeyEdOkay;
  66.     SetDefaultButton(button);
  67.     
  68.     button = new (CButton);                                    //  Set up the cancel button
  69.     button->IButton(CANCEL_BUTTON_ID, this, this);
  70.     button->Offset(220, FUNCTION_HEIGHT + 40, TRUE);
  71.     button->SetClickCmd (cmdCancel);
  72.     button->helpResIndex = kKeyEdCancel;
  73.     
  74.     CEditText *text = new(CEditText);                        //  Set up the Key text
  75.     text->IEditText(this, this, 65, 16,
  76.                     0, 10, sizFIXEDLEFT, sizFIXEDTOP, -1);
  77.     text->SetTextString("\pKey:");
  78.     text->SetFontNumber(systemFont);
  79.     text->SetFontSize(12);
  80.     text->SetWantsClicks(FALSE);
  81.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  82.     text->SetAlignCmd(cmdAlignRight);
  83.     
  84.     key_pane = new(CModifierKeyPane);                        //  Set up the key pane
  85.     key_pane->IModifierKeyPane(this, this, 71, 10,
  86.                         sizFIXEDLEFT, sizFIXEDTOP, -1);
  87.     key_pane->SetKey(KeyF1);
  88.     key_pane->SetModifiers(0);
  89.     key_pane->helpResIndex = kKeyEdKey;
  90.  
  91.     text = new(CEditText);                                    //  Set up the Function text
  92.     text->IEditText(this, this, 65, 16,
  93.                     0, FUNCTION_HEIGHT, sizFIXEDLEFT, sizFIXEDTOP, -1);
  94.     text->SetTextString("\pFunction:");
  95.     text->SetFontNumber(systemFont);
  96.     text->SetFontSize(12);
  97.     text->SetWantsClicks(FALSE);
  98.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  99.     text->SetAlignCmd(cmdAlignRight);
  100.  
  101.     short cursor = 70;
  102.     direction_popup = new (CStdPopupPane);                    //  Set up the direction menu
  103.     direction_popup->IStdPopupPane(
  104.                             DIRECTION_MENU_ID, this, this,
  105.                             kAutoSize, kAutoSize, cursor, FUNCTION_HEIGHT);
  106.     direction_popup->helpResIndex = kKeyEdDirection;
  107.     cursor += 105;
  108.     
  109.     text = new(CEditText);                                    //  Set up the [ text
  110.     text->IEditText(this, this, 100, 16, cursor, FUNCTION_HEIGHT,
  111.                         sizFIXEDLEFT, sizFIXEDTOP, -1);
  112.     text->SetTextString("\p[");
  113.     text->SetFontNumber(systemFont);
  114.     text->SetFontSize(12);
  115.     text->SetWantsClicks(FALSE);
  116.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  117.     cursor += 12;
  118.  
  119.     dimension_text = new(CIntegerText);                        //  Set up the dimension text
  120.     dimension_text->IIntegerText(this, this, 40, 16, 
  121.                         cursor, FUNCTION_HEIGHT,
  122.                             sizFIXEDLEFT, sizFIXEDTOP, -1);
  123.     dimension_text->SetFontNumber(systemFont);
  124.     dimension_text->SetFontSize(12);
  125.     dimension_text->SpecifyDefaultValue(3);
  126.     dimension_text->helpResIndex = kKeyEdDimension;
  127.     cursor += 44;
  128.  
  129.     text = new(CEditText);                                    //  Set up the : text
  130.     text->IEditText(this, this, 100, 16, cursor, FUNCTION_HEIGHT,
  131.                         sizFIXEDLEFT, sizFIXEDTOP, -1);
  132.     text->SetTextString("\p:");
  133.     text->SetFontNumber(systemFont);
  134.     text->SetFontSize(12);
  135.     text->SetWantsClicks(FALSE);
  136.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  137.     cursor += 11;
  138.  
  139.     angle_text = new(CDialogText);                            //  Set up the angle text
  140.     angle_text->IDialogText(this, this, 40, 16, 
  141.                         cursor, FUNCTION_HEIGHT,
  142.                             sizFIXEDLEFT, sizFIXEDTOP, -1);
  143.     angle_text->SetFontNumber(systemFont);
  144.     angle_text->SetFontSize(12);
  145.     angle_text->helpResIndex = kKeyEdAngle;
  146.     cursor += 44;
  147.  
  148.     text = new(CEditText);                                    //  Set up the "] by" text
  149.     text->IEditText(this, this, 100, 16, cursor, FUNCTION_HEIGHT,
  150.                         sizFIXEDLEFT, sizFIXEDTOP, -1);
  151.     text->SetTextString("\p] by");
  152.     text->SetFontNumber(systemFont);
  153.     text->SetFontSize(12);
  154.     text->SetWantsClicks(FALSE);
  155.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  156.     cursor += 33;
  157.  
  158.     increment_text = new(CIntegerText);                        //  Set up the editable increment text
  159.     increment_text->IIntegerText(this, this, 60, 16, 
  160.                         cursor, FUNCTION_HEIGHT,
  161.                             sizFIXEDLEFT, sizFIXEDTOP, -1);
  162.     increment_text->SetFontNumber(systemFont);
  163.     increment_text->SetFontSize(12);
  164.     increment_text->SpecifyDefaultValue(1);
  165.     increment_text->helpResIndex = kKeyEdIncrement;
  166.  
  167.     key_pane->SetKey(key->key_code);                                //  Set the key
  168.     key_pane->SetModifiers(key->modifiers);                            //  Set the modifiers
  169.     
  170.     dimension_text->SetIntValue(key->dimension);                    //  Set the dimension
  171.  
  172.     if (key->angle == 0)
  173.         angle_text->SetTextString("\pP");                            //  Set perspective change
  174.     else
  175.         {
  176.         Str255 angle_string;
  177.         NumToString(key->angle, angle_string);
  178.         angle_text->SetTextString(angle_string);                    //  Set the angle text
  179.         }
  180.     
  181.     increment_text->SetIntValue(
  182.                         (key->increment >= 0) ?
  183.                             key->increment : -key->increment);        //  Set increment
  184.  
  185.     direction_popup->GetMenu()->SelectItem(
  186.                         (key->increment >= 0) ? 1 : 2, pmForceOn);    //  Set direction
  187.  
  188.     gDecorator->CenterWindow (this);                        //  Center the window on the screen
  189.  
  190. }    //=== CEditKeyControlsDialog::IEditKeyControlsDialog() ===\\
  191.  
  192.  
  193.  
  194. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195. //| CEditKeyControlsDialog::UpdateKey
  196. //|
  197. //| Purpose: Sets the key to match the settings chosen in the dialog.
  198. //|
  199. //| Parameters: key: receives the settings chosen in the dialog
  200. //|______________________________________________________________________________
  201.  
  202. void CEditKeyControlsDialog::UpdateKey(key_control_struct *key)
  203. {
  204.  
  205.     key->key_code = key_pane->GetKey();                                //  Get the key
  206.     key->modifiers = key_pane->GetModifiers();                        //  Get the modifiers
  207.  
  208.     key->dimension = dimension_text->GetIntValue();                    //  Get the dimension
  209.     key->increment = increment_text->GetIntValue();                    //  Get the increment
  210.     if (direction_popup->GetMenu()->GetCheckedItem() == 2)
  211.         key->increment = -key->increment;                            //  Check for Decrease
  212.  
  213.     Str255 angle_string;
  214.     angle_text->GetTextString(angle_string);                        //  Get the angle as a string
  215.     if ((angle_string[0] == '\1') &&
  216.             (toupper(angle_string[1]) == 'P'))
  217.         key->angle = 0;                                                //  Perspective change
  218.     else
  219.         {
  220.         long angle_long;
  221.         StringToNum(angle_string, &angle_long);                        //  Convert to number
  222.         if (angle_long >= key->dimension)
  223.             angle_long = key->dimension - 1;                        //  Clip to dimension
  224.         if (angle_long <= 0)
  225.             angle_long = 1;                                            //  Clip to angle == 1
  226.         key->angle = angle_long;
  227.         }
  228.  
  229. }    //==== CEditKeyControlsDialog::UpdateKey() ====\\